import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import 'package:my_flu01/common/MyButton.dart';
import '../common/DataBean.dart';
import '../models/list_result.dart';
import '../models/list_result2.dart';
import '../models/product2.dart';
import '../models/product_model.dart';
import '../utils/api.dart';

/**
 * @author[Administrator]
 * @version[创立日期，2023/9/7 8:58]
 * @function[功用简介 ]
 * https://blog.csdn.net/a526001650a/article/details/127391917 布局
 **/
class ListViewBuilderPage extends StatefulWidget {
  const ListViewBuilderPage({Key? key}) : super(key: key);

  @override
  _listViewPageState createState() => _listViewPageState();
}

class _listViewPageState extends State<ListViewBuilderPage> {

 //late ListResult<DataBean> jsonNews=getList();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("listView"),
        ),
        body:
              ListView.builder(
                itemCount: listData.length,
                itemBuilder: this._getListData,
              )
        // This trailing comma makes auto-formatting nicer for build methods.
    );
  }


//使用ListView.builder实现：
  Widget _getListData(context, index) {
    return ListTile(
        leading: Image.network(listData[index]["imageUrl"]), // 显示在title之前
        title: Text(listData[index]['title']),
        subtitle: Text(listData[index]["author"]),
    //        显示在title之后
        trailing: Icon(Icons.phone),
      //再加子集
    );
  }
}



List listData=[
  {
    "title":"Candy Shop",
    "author":"Mohamed Chahin",
    "imageUrl":"https://www.itying.com/images/flutter/1.png",
  },
  {
    "title":"Candy Shop",
    "author":"Mohamed Chahin",
    "imageUrl":"https://www.itying.com/images/flutter/2.png",
  },
  {
    "title":"Candy Shop",
    "author":"Mohamed Chahin",
    "imageUrl":"https://www.itying.com/images/flutter/3.png",
  },
  {
    "title":"Candy Shop",
    "author":"Mohamed Chahin",
    "imageUrl":"https://www.itying.com/images/flutter/4.png",
  },{
    "title":"Candy Shop",
    "author":"Mohamed Chahin",
    "imageUrl":"https://www.itying.com/images/flutter/5.png",
  }
];

